<?php
class up_dataModel extends model
{
	public function __construct(){
		parent::__construct();
		$this->publics = $this->loadModel('publics');			//公共数据查询
		$this->p = $this->app->loadClass('proving');
		
		$this->rone = 'http://127.0.0.1/rone/';
		$this->regieapp_case = 'http://127.0.0.1/regieapp_case/';
	}
	
	//添加apcd商户
	public function get_customer($data){
		
		foreach($data->results as $k => $v){
			$id = $this->dao->uuid();
			$this->dao->insert('apcd_customer')
				->set('id')->eq($id)
				->set('companyName')->eq($v->companyName)
				->set('clientName')->eq($v->clientName)
				->set('clientCode')->eq($v->clientCode)
				->set('address')->eq($v->address)
				->set('addtime')->eq(time())
				->exec();
				
			echo($v->companyName.'..................<br />');
			ob_flush();
			flush();
		}
		
	}
	
	//添加任apcd务类型
	public function get_task_data($data){
		foreach($data as $k => $v){
			$id = $this->dao->uuid();
			$this->dao->insert('apcd_task_type')
				->set('id')->eq($id)
				->set('taskcode')->eq($v->BASE_CODE)
				->set('typename')->eq($v->CODE_NAME)
				->set('addtime')->eq(time())
				->exec();
				
			echo($v->CODE_NAME.'..................<br />');
			ob_flush();
			flush();
		}
	}
	
	//获取网格apcd数据
	public function get_data_gride($data,$userid){
		foreach($data as $k => $v){
			$info = $this->dao->select('*')->from('apcd_gride')->where('tagId')->eq($v->tagId)->fetch();
			if($info){
				$this->dao->update('apcd_gride')
					->set('tagName')->eq($v->tagName)
					->set('userid')->eq($userid)
					->set('addtime')->eq(time())
					->where('tagId')->eq($v->tagId)
					->exec();
			}else{
				$id = $this->dao->uuid();
				$this->dao->insert('apcd_gride')
					->set('id')->eq($id)
					->set('tagId')->eq($v->tagId)
					->set('tagName')->eq($v->tagName)
					->set('userid')->eq($userid)
					->set('addtime')->eq(time())
					->exec();
			}
			echo($v->tagName.'..................<br />');
			ob_flush();
			flush();
		}
		
	}
	
	//查询网格
	public function get_user_gride(){
		return $this->dao->select('*')->from('apcd_gride')->fetchAll();
	}
	
	//获取网格商户
	public function get_gride_customer($data,$userid,$gridcode){
		foreach($data as $k => $v){
			$info = $this->dao->select('*')->from('apcd_gride_customer')->where('clientCode')->eq($v->clientCode)->fetch();
			
			if($info){
				$this->dao->update('apcd_gride_customer')
					->set('userid')->eq($userid)
					->set('address')->eq($v->address)
					->set('clientName')->eq($v->clientName)
					->set('gridCode')->eq($v->gridCode)
					->set('apcd_grid_name')->eq($gridcode)
					->set('gridName')->eq($v->gridName)
					->set('groupType')->eq($v->groupType)
					->set('groupUUID')->eq($v->groupUUID)
					->set('monthCheckNum')->eq($v->monthCheckNum)
					->set('phone')->eq($v->phone)
					->set('shopName')->eq($v->shopName)
					->set('workState')->eq($v->workState)
					->set('licenseCode')->eq($v->licenseCode)
					->set('runId')->eq($v->runId)
					->set('planId')->eq($v->planId)
					->set('taskDescription')->eq($v->taskDescription)
					->set('taskId')->eq($v->taskId)
					->set('taskSource')->eq($v->taskSource)
					->set('taskSourceName')->eq($v->taskSourceName)
					->set('taskType')->eq($v->taskType)
					->set('addtime')->eq(time())
					->where('clientCode')->eq($v->clientCode)
					->exec();
			}else{
				$id = $this->dao->uuid();
				$this->dao->insert('apcd_gride_customer')
					->set('id')->eq($id)
					->set('userid')->eq($userid)
					->set('address')->eq($v->address)
					->set('clientCode')->eq($v->clientCode)
					->set('clientName')->eq($v->clientName)
					->set('gridCode')->eq($v->gridCode)
					->set('apcd_grid_name')->eq($gridcode)
					->set('gridName')->eq($v->gridName)
					->set('groupType')->eq($v->groupType)
					->set('groupUUID')->eq($v->groupUUID)
					->set('monthCheckNum')->eq($v->monthCheckNum)
					->set('phone')->eq($v->phone)
					->set('shopName')->eq($v->shopName)
					->set('workState')->eq($v->workState)
					->set('licenseCode')->eq($v->licenseCode)
					->set('runId')->eq($v->runId)
					->set('planId')->eq($v->planId)
					->set('taskDescription')->eq($v->taskDescription)
					->set('taskId')->eq($v->taskId)
					->set('taskSource')->eq($v->taskSource)
					->set('taskSourceName')->eq($v->taskSourceName)
					->set('taskType')->eq($v->taskType)
					->set('addtime')->eq(time())
					->exec();
			}
			
				
			echo($v->shopName.'..................<br />');
			ob_flush();
			flush();
		}
		
	}
	
	
	//获取商户
	public function select_t_customer($clientCode){
		$clientCode = explode(',',$clientCode);
		$customer_id = '';
		foreach($clientCode as $v){
			$customer_id .= "'".$v."'".",";
		}
		$customer_id = substr($customer_id,0,strlen($customer_id)-1);
		
		return $this->dao->select("clientCode,clientName,gridCode,groupType,groupUUID,licenseCode")->from('apcd_gride_customer')->where("clientCode in ($customer_id)")->fetchAll();
		
		return $this->dao->select("address,taskType,clientCode,clientName,gridCode,gridName,groupType,groupUUID,licenseCode,monthCheckNum,phone,runId,taskDescription,taskId,taskSource,taskSourceName,true as checked,0 as flag, DATE_FORMAT(NOW(),'%Y-%m-%d') as endDate,DATE_FORMAT(NOW(),'%Y-%m-%d') as startDate")->from('apcd_gride_customer')->where("clientCode in ($customer_id)")->fetchAll();
	}
	
	//获取xcyc日常任务数据
	public function task_info_xcyc($planid,$squadron){
		$return = array();
		
		//获取任务详情
		$detail = $this->dao->select("group_concat(taskcon,'<br />') as taskcon")->from('zm_plan_details')->where('plan')->eq($planid)->andWhere("squadron = '$squadron'")->andWhere('status = 0')->groupBy('plan')->fetch();
		$return['detail'] = $detail->taskcon;
		
		//获取任务执行商户
		$customer = $this->dao->select("group_concat(license) as license")->from('zm_plan_business')->where('plan')->eq($planid)->andWhere('squadronid')->eq($squadron)->andWhere('status = 0')->groupBy('plan')->fetch();
		$return['customer'] = @$customer->license;
		
		//日计划执行成员
		$user = $this->dao->select('userid')->from('zm_plan_workers')->where('plan')->eq($planid)->andWhere('status = 0')->fetchAll();
		$return['user'] = $user;
		
		$date = $this->dao->select('*')->from('zm_day_plan')->where('id')->eq($planid)->fetch();
		$return['date'] = $date->thedate;
		
		$return['squadron'] = $squadron;
		return $return;
	}
	
	//查询apcd平台执行用户数据
	public function find_apcd_user($task_info){
		
		$xcyc_user_id = '';
		foreach($task_info['user'] as $v){
			$xcyc_user_id .= "'".$v['userid']."'".",";
		}
		$xcyc_user_id = substr($xcyc_user_id,0,strlen($xcyc_user_id)-1);
		$user = $this->dao->select('*')->from('apcd_user')->where("xcyc_user_id in ($xcyc_user_id)")->fetchAll();
		
		return $user;
	}
	
	//查询apcd平台执行用户数据
	public function find_apcd_user1($task_info){
		
		$xcyc_customer =  $task_info['customer'];
		$x_customers =  explode(',',$xcyc_customer);
		
		//判断商户是否存在
		if($x_customers[0]){
			$xc = '';
			foreach($x_customers as $v){
				$xc .= "'".$v."'".",";
			}
			$xc = substr($xc,0,strlen($xc)-1);
			
			$user = $this->dao->select('userid,GROUP_CONCAT(licenseCode) as licenseCode')->from('apcd_gride_customer')->where("licenseCode in ($xc)")->groupBy('userid')->fetchAll();
		}else{
			$user =$this->dao->select("c.apcd_app_userid as userid,'' as licenseCode")->from('zm_plan_execute')->alias('a')
				->leftJOin('zm_squadron')->alias('b')->on('a.squadron = b.squadron')
				->leftJoin('apcd_user')->alias('c')->on('c.squadronid = b.id')
				->where('a.id')->eq($task_info['squadron'])
				->fetchAll();
			
		}
		
		return $user;
	}
	
	public function get_task_pool_user($licenseno){
		
		return $this->dao->select('b.*')->from('zm_business')->alias('a')
			->leftJOin('apcd_user')->alias('b')->on('a.market = b.id')
			->where('a.license')->eq($licenseno)
			->andWhere('a.status = 0 and b.status = 0')
			->fetch();
	}
	
	//获取任务商户信息
	public function find_apcd_task_customer($xcyc_customer){
		$x_customers =  explode(',',$xcyc_customer);
		
		$xc = '';
		foreach($x_customers as $v){
			$xc .= "'".$v."'".",";
		}
		$xc = substr($xc,0,strlen($xc)-1);
		
		$customer = $this->dao->select('entname as ENT_NAME,address as ADDRESS,clientname as CLIENT_NAME,clientcode as CLIENT_CODE,clientphone as CLIENT_PHONE,licenseno as LICENSE_NO,gridname as GRID_NAME,gridid as GRID_ID,1 as IF_HAVE_LICENSE,0 as CHECKCNT,1 as PID')->from('apcd_customer')->where("licenseno in ($xc)")->fetchAll();
		
		foreach($customer as $k => $v){
			$customer[$k]->PID = $k+1;
		}

		return json_encode($customer);
	}
	
	//获取apcd平台任务池商户数据
	public function insert_apcd_customer($apcd_customer){
		$apcd_customer = $apcd_customer->rows;
		
		foreach($apcd_customer as $v){
			
			$res = $this->dao->select('*')->from('apcd_customer')->where('clientcode')->eq($v->CLIENT_CODE)->fetch();
			
			if($res){
				$this->dao->update('apcd_customer')
					->set('entname')->eq($v->ENT_NAME)
					->set('address')->eq($v->ADDRESS)
					->set('clientname')->eq($v->CLIENT_NAME)
					->set('clientphone')->eq($v->CLIENT_PHONE)
					->set('licenseno')->eq($v->LICENSE_NO)
					->set('gridname')->eq($v->GRID_NAME)
					->set('gridid')->eq($v->GRID_ID)
					->set('addtime')->eq(time())
					->where('clientcode')->eq($v->CLIENT_CODE)
					->exec();
			}else{
				$id = $this->dao->uuid();
				$this->dao->insert('apcd_customer')
					->set('id')->eq($id)
					->set('entname')->eq($v->ENT_NAME)
					->set('address')->eq($v->ADDRESS)
					->set('clientname')->eq($v->CLIENT_NAME)
					->set('clientcode')->eq($v->CLIENT_CODE)
					->set('clientphone')->eq($v->CLIENT_PHONE)
					->set('licenseno')->eq($v->LICENSE_NO)
					->set('gridname')->eq($v->GRID_NAME)
					->set('gridid')->eq($v->GRID_ID)
					->set('addtime')->eq(time())
					->exec();
			}
			
			
				
			echo($v->ENT_NAME.'..................<br />');
			ob_flush();
			flush();
		}
		
	}
	
	//添加日志
	public function insert_apcd_log_to_xcyc($data,$userid,$date){
		if(!empty($data)){
			foreach($data as $v){
				
				$id = $this->dao->uuid();
				$log_info = $this->dao->select('count(*) as n')->from('apcd_day_log')->where('id')->eq($v->logUuid)->fetch();
				
				if($log_info->n == 0){
					$this->dao->insert('apcd_day_log')
						->set('id')->eq($v->logUuid)
						->set('apcd_userid')->eq($userid)
						->set('mainCase')->eq($v->mainCase)
						->set('workSummary')->eq($v->workSummary)
						->set('checkPerson')->eq($v->approvalPersonName)
						->set('reviewAdvise')->eq($v->reviewAdvise)
						->set('submitPersonName')->eq($v->submitPersonName)
						->set('date')->eq($date)
						->set('addtime')->eq(time())
						->exec();
				}
				echo($v->submitPersonName.'..................<br />');
				ob_flush();
				flush();
				
			}
		}
		
	}
	 
	 
	//更新检查结果
	public function updata_checked($data){
		$start = strtotime(date('Y-m-d'));
		$end = time();
		
		foreach($data as $v){
			echo('更新'.$v->shopName.'商户检查结果'.'..................<br />');
			ob_flush();
			flush();
			if($v->endTime && $v->startTime && $v->taskStatus == 3){
				$this->dao->update('zm_plan_business')
					->set('situation')->eq('1')
					->where("license")->eq($v->clientCode)
					->andWhere("status = 0")
					->andWhere("addtime between $start and $end")
					->exec();
			}
		}
	}
	
	//添加巡检信息
	public function insert_patrol_info($data,$tuser){
		$start = strtotime(date('Y-m-d'));
		$end = time();
		
		//存在内容的下标数组
		$content_key = array(
			'3402040101' => '340204010101',		//字号名称
			'3402040102' => '340204010201',		//负责人姓名
			'3402040103' => '340204010301',		//经营场所
			'3402040104' => '340204010401',		//企业类型
			'34020402' => '3402040201',			//地址
			'34020403' => '3402040301'			//经营者信息
		);
		
		foreach($data as $v){
			echo('添加'.$v->shopName.'巡检信息'.'..................<br />');
			ob_flush();
			flush();
			
			//添加检查结果
			if($v->endTime && $v->startTime && $v->taskStatus == 3){		//判断检查结束
				
				$clientCode = $v->clientCode;								//商户许可证号
				$startTime = strtotime($v->startTime);						//开始时间
				$endTime = strtotime($v->endTime);							//结束时间
				
				foreach($v->workItemDataList as $value){
					if($value->workItemId == '34020101'){		//异常类型
						$abnormaltype = $value->value;
					}
					
					if($value->workItemId == '34020102'){		//流入问题备注
						$remarks1 = $value->value;
					}
					
					if($value->workItemId == '34020202'){		//流出问题备注	
						$remarks2 = $value->value;
					}
					
					if($value->workItemId == '34020313'){		//规范经营问题备注
						$remarks3 = $value->value;
					}
				}
				
				$task_info = $this->dao->select('*')->from('zm_plan_business')
					->where("license")->eq($clientCode)
					->andWhere("status = 0")
					->andWhere("addtime between $start and $end")
					->fetch();
				
				$plan_id = '';
				$squadronid = '';
				if($task_info){
					$plan_id = $task_info->plan;				//计划id
					$squadronid = $task_info->squadronid;		//中队id
				}
				
				
				//添加巡检主记录
				$xid = $this->dao->uuid();
				$this->dao->insert('zm_patrol')
					->set('id')->eq($xid)
					->set('plan')->eq($plan_id)
					->set('business')->eq($task_info->business)
					->set('squadron')->eq($squadronid)
					->set('submitterid')->eq($tuser->xcyc_user_id)
					->set('submitter')->eq($tuser->name)
					->set('sources')->eq(1)
					->set('starttime')->eq($startTime)
					->set('endtime')->eq($endTime)
					->set('remarks1')->eq($remarks1)
					->set('remarks2')->eq($remarks2)
					->set('remarks3')->eq($remarks3)
					->set('abnormaltype')->eq($abnormaltype)
					->set('reporttime')->eq(time())
					->set('addtime')->eq(time())
					->exec();
				
				//添加巡检商户信息
				$sid = $this->dao->uuid();
				$this->dao->insert('zm_patrol_business')
					->set('id')->eq($sid)
					->set('patrol')->eq($xid)
					->set('plan')->eq($plan_id)
					->set('squadronid')->eq($squadronid)
					->set('business')->eq($task_info->business)
					->set('code')->eq($task_info->code)
					->set('name')->eq($task_info->name)
					->set('legal')->eq($task_info->legal)
					->set('tel')->eq($task_info->tel)
					->set('image')->eq($task_info->image)
					->set('photo')->eq($task_info->photo)
					->set('address')->eq($task_info->address)
					->set('license')->eq($task_info->license)
					->set('expire')->eq($task_info->expire)
					->set('remind')->eq($task_info->remind)
					->set('squadron')->eq($task_info->squadron)
					->set('grid')->eq($task_info->grid)
					->set('route')->eq($task_info->route)
					->set('qrcode')->eq($task_info->qrcode)
					->set('category')->eq($task_info->category)
					->set('level')->eq($task_info->level)
					->set('district')->eq($task_info->district)
					->set('operating')->eq($task_info->operating)
					->set('mapx')->eq($task_info->mapx)
					->set('mapy')->eq($task_info->mapy)
					->set('company')->eq($task_info->company)
					->set('manager')->eq($task_info->manager)
					->set('addtime')->eq(time())
					->exec();
					
				//添加巡检信息详情
				foreach($v->workItemDataList as $value){
					if($value->workItemId == '34020101'){		//异常类型
						$abnormaltype = $value->value;
					}
					if($value->value == '1'){
						$content = '';
						
						$check_info = $this->dao->select('*')->from('zm_check_project')
							->where('id')->eq($value->workItemId)
							->andWhere('status = 0')
							->fetch();
							
							//如果存在内容值获取内容
							if(array_key_exists($value->workItemId,$content_key)){
								foreach($v->workItemDataList as $sv){
									if($sv->workItemDataList == $content_key[$value->workItemId]){
										$content = $sv->value;
									}
								}
							}
							
							if($check_info){
								
								$dtid = $this->dao->uuid();
								$this->dao->insert('zm_patrol_details')
									->set('id')->eq($dtid)
									->set('patrol')->eq($xid)
									->set('project')->eq($check_info->id)
									->set('inspection')->eq($check_info->inspection)
									->set('handlestate')->eq(0)
									->set('result')->eq('')
									->set('content')->eq($content)
									->set('addtime')->eq(time())
									->exec();
									
									
								/*********************设置检查积分*************************/
								//获取商户对应人员中队
								$object_info = $this->dao->select('a.id,a.market,c.squadronid*')->from('zm_business')->alias('a')
									->leftJoin('apcd_user')->alias('b')->on('a.market = b.id')
									->where('a.id')->eq($task_info->business)
									->fetch();
								
								//查询商户积分信息
								$change_number = $this->dao->select('score')->from('zm_business_corerule')->where('checkid')->eq($check_info->id)->andWhere('status = 0 and violation = 1')->fetch();
								
								$change_number->score = 1;
								
								if($object_info){
								
									//商户积分信息
									$score_s_tid = $this->dao->uuid();
									$this->dao->insert('zm_business_core')
										->set('id')->eq($score_s_tid)
										->set('business')->eq($task_info->business)
										->set('code')->eq($task_info->code)
										->set('name')->eq($task_info->name)
										->set('legal')->eq($task_info->legal)
										->set('tel')->eq($task_info->tel)
										->set('image')->eq($task_info->image)
										->set('photo')->eq($task_info->photo)
										->set('address')->eq($task_info->address)
										->set('license')->eq($task_info->license)
										->set('expire')->eq($task_info->expire)
										->set('remind')->eq($task_info->remind)
										->set('squadron')->eq($task_info->squadron)
										->set('grid')->eq($task_info->grid)
										->set('route')->eq($task_info->route)
										->set('qrcode')->eq($task_info->qrcode)
										->set('category')->eq($task_info->category)
										->set('level')->eq($task_info->level)
										->set('district')->eq($task_info->district)
										->set('operating')->eq($task_info->operating)
										->set('mapx')->eq($task_info->mapx)
										->set('mapy')->eq($task_info->mapy)
										->set('company')->eq($task_info->company)
										->set('manager')->eq($task_info->manager)
										->set('checkid')->eq($check_info->id)
										->set('checktype')->eq($check_info->checktype)
										->set('inspection')->eq($check_info->inspection)
										->set('sources')->eq(1)
										->set('origin')->eq($xid)
										->set('score')->eq($change_number->score)
										->set('addtime')->eq(time())
										->exec();
										
									
									$user = $this->dao->select('b.*')->from('apcd_user')->alias('a')
										->leftJoin('zm_user')->alias('b')->on('a.xcyc_user_id = b.id')
										->where('a.id')->eq($object_info->market)->fetch();
									
									//人员积分信息
									$score_u_tid = $this->dao->uuid();
									$this->dao->insert('zm_user_points')
										->set('id')->eq($score_u_tid)
										->set('userid')->eq($user->id)
										->set('code')->eq($user->code)
										->set('name')->eq($user->name)
										->set('pwd')->eq($user->pwd)
										->set('tel')->eq($user->tel)
										->set('company')->eq($user->company)
										->set('department')->eq($user->department)
										->set('squadron')->eq($user->squadron)
										->set('grid')->eq($user->grid)
										->set('photo')->eq($user->photo)
										->set('phone')->eq($user->phone)
										->set('serial')->eq($user->serial)
										->set('licensetype')->eq($user->licensetype)
										->set('usertype')->eq($user->usertype)
										->set('audit')->eq($user->audit)
										->set('checkid')->eq($check_info->id)
										->set('checktype')->eq($check_info->checktype)
										->set('inspection')->eq($check_info->inspection)
										->set('sources')->eq(1)
										->set('origin')->eq($xid)
										->set('score')->eq(1)					//人员积分
										->set('addtime')->eq(time())
										->exec();
										
									$squadron = $this->dao->select('*')->from('zm_squadron')->where('id')->eq($object_info->squadronid)->fetch();
									
									//中队积分信息
									$score_z_tid = $this->dao->uuid();
									$this->dao->insert('zm_squadron_points')
										->set('id')->eq($score_z_tid)
										->set('squadronid')->eq($squadron->id)
										->set('squadron')->eq($squadron->squadron)
										->set('checkid')->eq($check_info->id)
										->set('checktype')->eq($check_info->checktype)
										->set('inspection')->eq($check_info->inspection)
										->set('sources')->eq(1)
										->set('origin')->eq($xid)
										->set('score')->eq(1)
										->set('addtime')->eq(time())
										->exec();
								}
								
							}
							
					}
				}
				/****************添加巡检信息详情结束*******************/
				
				//添加卷烟罚没信息
				if(!empty($v->problemCigRegList)){
					foreach($v->problemCigRegList as $fv){
						
						//获取卷烟id
						$cid = '';
						$cigarette = $this->dao->select('*')->from('zm_cigarette')->where('name')->eq($fv->cigName)->fetch();
						if($cigarette){
							$cid = $cigarette->id;
						}
						
						if($fv->workItemId == '340201010101'){
							$cigarettetype = 1;		//假烟
						}
						
						if($fv->workItemId == '340201010201'){
							$cigarettetype = 2;		//走私烟
						}
						
						if($fv->workItemId == '340201010301'){
							$cigarettetype = 3;		//真烟
						}
						
						//添加罚没信息
						$fid = $this->dao->uuid();
						$this->dao->insert('zm_forfeiture')
							->set('id')->eq($fid)
							->set('patrol')->eq($xid)
							->set('business')->eq($task_info->business)
							->set('cigarette')->eq($cid)
							->set('cigarettetype')->eq($cigarettetype)
							->set('number')->eq($fv->amountTiao)
							->set('source')->eq($fv->source)
							->set('standard')->eq($fv->cigName)
							->set('addtime')->eq(time())
							->exec();
							
						//卷烟罚没商户信息表数据添加
						$sid = $this->dao->uuid();
						$this->dao->insert('zm_patrol_business')
							->set('id')->eq($sid)
							->set('patrol')->eq($xid)
							->set('forfeiture')->eq($fid)
							->set('business')->eq($task_info->business)
							->set('code')->eq($task_info->code)
							->set('name')->eq($task_info->name)
							->set('legal')->eq($task_info->legal)
							->set('tel')->eq($task_info->tel)
							->set('image')->eq($task_info->image)
							->set('photo')->eq($task_info->photo)
							->set('address')->eq($task_info->address)
							->set('license')->eq($task_info->license)
							->set('expire')->eq($task_info->expire)
							->set('remind')->eq($task_info->remind)
							->set('squadron')->eq($task_info->squadron)
							->set('grid')->eq($task_info->grid)
							->set('route')->eq($task_info->route)
							->set('qrcode')->eq($task_info->qrcode)
							->set('category')->eq($task_info->category)
							->set('level')->eq($task_info->level)
							->set('district')->eq($task_info->district)
							->set('operating')->eq($task_info->operating)
							->set('mapx')->eq($task_info->mapx)
							->set('mapy')->eq($task_info->mapy)
							->set('company')->eq($task_info->company)
							->set('manager')->eq($task_info->manager)
							->set('addtime')->eq(time())
							->exec();
						
						//添加罚没卷烟信息表数据
						if($cigarette){
							$sid = $this->dao->uuid();
							$this->dao->insert('m_forfeitureinfo')
								->set('id')->eq($sid)
								->set('patrol')->eq($xid)
								->set('forfeiture')->eq($fid)
								->set('cigarette')->eq($cigarette->id)
								->set('code')->eq($cigarette->code)
								->set('name')->eq($cigarette->name)
								->set('brand')->eq($cigarette->brand)
								->set('bar')->eq($cigarette->bar)
								->set('facturer')->eq($cigarette->facturer)
								->set('measurement')->eq($cigarette->measurement)
								->set('wholesale')->eq($cigarette->wholesale)
								->set('retail')->eq($cigarette->retail)
								->set('category')->eq($cigarette->category)
								->set('addtime')->eq(time())
								->exec();
						}
							
					}
					
				}
				/*******************添加卷烟罚没信息结束*********************/
				
				
			}
			/*****************添加检查结果结束****************/
			
			
		}
		
		
	}
	
	//排序对比
	public function sort_workItemDataList($data){
		$p = $this->app->loadClass('proving');
		$r = array();
		foreach($data as $v){
			
			if($v->clientName == '杜金梅' || $v->clientName == '陈德福'){
				
				$a = $p->objectToArrayK($v->workItemDataList,'workItemId');
				ksort($a);
				$a['name'] = $v->clientName;
				a($a);
				echo  '------------------------------------------------------------------------';
			}
			
		}
		
	}
	
	//查询apcd平台所有用户信息
	public function find_apcd_all_user($where = ''){
		return $this->dao->select('*')->from('apcd_user')->where("status = 0 $where")->fetchAll();
	}
	
	//更新apcd用户信息
	public function updata_apcd_userinfo($data,$xcyc_user_id){
		$this->dao->update('apcd_user')
			->set('apcd_app_userid')->eq($data->userId)
			->set('cityCode')->eq($data->unitCode)
			->set('userDeptCode')->eq($data->orgCode)
			//->set('orgName')->eq($data->orgName)
			->set('name')->eq($data->userName)
			->where('xcyc_user_id')->eq($xcyc_user_id)
			->exec();
			
		return true;
	}
	
	//二级网格入库
	public function update_gride_2($data){
		$time = date('Y-m-d H:i:s');
		/* echo('三级网格数据入库<br />');
		ob_flush();
		flush();	 */
		$this->push_div_content('.scorpall','二级网格数据入库<br />');
		
		foreach($data as $v){
			/* echo($v->text.'。。。。。<br />');
			ob_flush();
			flush(); */	
			$this->push_div_content('.scorpall',$v->text.'。。。。。<br />');
			
			$info = $this->dao->select('*')->from('t_comm_zm_area')->where('id')->eq($v->id)->andWhere('status = 0')->fetch();
			
			if($info){
				$this->dao->update('t_comm_zm_area')
					->set('squadron')->eq($v->text)
					->set('provincecode')->eq($v->attributes->PROVINCE_CODE)
					->set('citycode')->eq($v->attributes->CITY_CODE)
					->set('countrycode')->eq($v->attributes->COUNTRY_CODE)
					->set('deptcode')->eq($v->attributes->DEPT_CODE)
					->set('update_date')->eq($time)
					->where('id')->eq($v->id)
					->exec();
			}else{
				$this->dao->insert('t_comm_zm_area')
					->set('id')->eq($v->id)
					->set('squadron')->eq($v->text)
					->set('provincecode')->eq($v->attributes->PROVINCE_CODE)
					->set('citycode')->eq($v->attributes->CITY_CODE)
					->set('countrycode')->eq($v->attributes->COUNTRY_CODE)
					->set('deptcode')->eq($v->attributes->DEPT_CODE)
					->set('create_date')->eq($time)
					->exec();
			}
			
		}
		
		
	}
	
	
	//三级网格入库
	public function update_gride_3($data){
		$time = date('Y-m-d H:i:s');
		
		/* echo('三级网格数据入库<br />');
		ob_flush();
		flush();	 */
		$this->push_div_content('.scorpall','三级网格数据入库<br />');
		
		foreach($data as $v){
			/* echo($v->text.'。。。。。<br />');
			ob_flush();
			flush(); */	
			$this->push_div_content('.scorpall',$v->text.'。。。。。<br />');
			
			$info = $this->dao->select('*')->from('t_comm_zm_squadron')->where('id')->eq($v->id)->andWhere('status = 0')->fetch();
			
			if($info){
				$this->dao->update('t_comm_zm_squadron')
					->set('squadron')->eq($v->text)
					->set('provincecode')->eq($v->attributes->PROVINCE_CODE)
					->set('citycode')->eq($v->attributes->CITY_CODE)
					->set('countrycode')->eq($v->attributes->COUNTRY_CODE)
					->set('deptcode')->eq($v->attributes->DEPT_CODE)
					->set('update_date')->eq($time)
					->where('id')->eq($v->id)
					->exec();
			}else{
				$this->dao->insert('t_comm_zm_squadron')
					->set('id')->eq($v->id)
					->set('squadron')->eq($v->text)
					->set('provincecode')->eq($v->attributes->PROVINCE_CODE)
					->set('citycode')->eq($v->attributes->CITY_CODE)
					->set('countrycode')->eq($v->attributes->COUNTRY_CODE)
					->set('deptcode')->eq($v->attributes->DEPT_CODE)
					->set('create_date')->eq($time)
					->exec();
			}
			
		}
		
		
	}
	
	//四级网格入库
	public function update_gride_4($data,$squadronid){
		$time = date('Y-m-d H:i:s');
		// echo('四级网格数据入库<br />');
		// ob_flush();
		// flush();	
		$this->push_div_content('.scorpall','四级网格数据入库<br />');
		
		foreach($data as $v){
			/* echo($v->text.'。。。。。<br />');
			ob_flush();
			flush();	 */
			$this->push_div_content('.scorpall',$v->text.'。。。。。<br />');
			
			$info = $this->dao->select('*')->from('t_comm_zm_apcd_user')->where('id')->eq($v->id)->andWhere('status = 0')->fetch();
			
			if($info){
				$this->dao->update('t_comm_zm_apcd_user')
					->set('name')->eq($v->text)
					->set('provincecode')->eq($v->attributes->PROVINCE_CODE)
					->set('cityCode')->eq($v->attributes->CITY_CODE)
					->set('countrycode')->eq($v->attributes->COUNTRY_CODE)
					->set('userDeptCode')->eq($v->attributes->DEPT_CODE)
					->set('squadronid')->eq($squadronid)
					->set('update_date')->eq($time)
					->where('id')->eq($v->id)
					->exec();
			}else{
				$this->dao->insert('t_comm_zm_apcd_user')
					->set('id')->eq($v->id)
					->set('name')->eq($v->text)
					->set('provincecode')->eq($v->attributes->PROVINCE_CODE)
					->set('cityCode')->eq($v->attributes->CITY_CODE)
					->set('countrycode')->eq($v->attributes->COUNTRY_CODE)
					->set('userDeptCode')->eq($v->attributes->DEPT_CODE)
					->set('squadronid')->eq($squadronid)
					->set('create_date')->eq($time)
					->exec();
			}
			
		}
		
		
	}
	
	
	//五级网格入库
	public function update_gride_5($data,$squadronid,$userid){
		$time = date('Y-m-d H:i:s');
		/* echo('五级网格数据入库<br />');
		ob_flush();
		flush();	 */
		$this->push_div_content('.scorpall','五级网格数据入库<br />');
		$res = array();
		
		foreach($data as $k => $v){
			/* echo($v->text.'。。。。。<br />');
			ob_flush();
			flush(); */	
			$this->push_div_content('.scorpall',$v->text.'。。。。。<br />');
			$info = $this->dao->select('*')->from('t_comm_zm_grid')->where('id')->eq($v->id)->andWhere('status = 0')->fetch();
			
			$res[$k]['squadronid'] = $squadronid;
			$res[$k]['userid'] = $userid;
			$res[$k]['gride'] = $v->id;
			
			if($info){
				$this->dao->update('t_comm_zm_grid')
					->set('grid_address')->eq($v->text)
					->set('provincecode')->eq($v->attributes->PROVINCE_CODE)
					->set('citycode')->eq($v->attributes->CITY_CODE)
					->set('countrycode')->eq($v->attributes->COUNTRY_CODE)
					->set('deptcode')->eq($v->attributes->DEPT_CODE)
					->set('squadronid')->eq($squadronid)
					->set('userid')->eq($userid)
					->set('update_date')->eq($time)
					->where('id')->eq($v->id)
					->exec();
			}else{
				$this->dao->insert('t_comm_zm_grid')
					->set('id')->eq($v->id)
					->set('grid_address')->eq($v->text)
					->set('provincecode')->eq($v->attributes->PROVINCE_CODE)
					->set('citycode')->eq($v->attributes->CITY_CODE)
					->set('countrycode')->eq($v->attributes->COUNTRY_CODE)
					->set('deptcode')->eq($v->attributes->DEPT_CODE)
					->set('squadronid')->eq($squadronid)
					->set('userid')->eq($userid)
					->set('create_date')->eq($time)
					->exec();
			}
			
		}
		
		
		return $res;
	}
	
	
	//更新网格名称
	public function update_grid_nameK($data){
		
		foreach($data as $v){
			echo($v->GRID_NAME.'。。。。。<br />');
			ob_flush();
			flush();
			$this->dao->update('zm_grid')
				->set('grid')->eq($v->GRID_ID)
				->where('id')->eq($v->GRID_CODE)
				->exec();
			
		}
		
	}

	
	//从页面提取商户信息 史立鑫
	public function extract_data_old($data){
		//$data = strstr($data,'<table width="98%"');
		$data = strstr($data,'<table align="center"');
		list($data,) = explode('</table>',$data);
		//a($data);exit;
		preg_match_all('/<td.*>(.+)<\/td>/isU',$data,$tabTr);
		$tabTrData = $tabTr[1];
		
		if($tabTrData[17] == '租赁期限起止：'){
			$tabTrData[17] = $tabTrData[16];
			$tabTrData[15] = '';
			$tabTrData[19] = $tabTrData[18];
			$tabTrData[21] = $tabTrData[20];
			$tabTrData[23] = $tabTrData[22];
			$tabTrData[25] = $tabTrData[24];
			$tabTrData[27] = $tabTrData[26];
			$tabTrData[29] = $tabTrData[28];
			$tabTrData[31] = $tabTrData[30];
			$tabTrData[33] = $tabTrData[32];
			$tabTrData[35] = $tabTrData[34];
			$tabTrData[37] = $tabTrData[36];
			$tabTrData[39] = $tabTrData[38];
			$tabTrData[41] = $tabTrData[40];
			$tabTrData[43] = $tabTrData[42];
			$tabTrData[45] = $tabTrData[44];
			$tabTrData[47] = $tabTrData[46];
			$tabTrData[49] = $tabTrData[48];
			$tabTrData[51] = @$tabTrData[50];
		}
		
		if($tabTrData[13] == '经营场所地址：'){
			$tabTrData[13] = $tabTrData[14];
		}
		
		if($tabTrData[11] == '与住所相独立：'){
			$tabTrData[11] = $tabTrData[12];
		}
		
		if($tabTrData[15] == '经营场地权属：'){
			$tabTrData[15] = $tabTrData[16];
		}
		
		if($tabTrData[17] == '经营面积（平方米）：'){
			$tabTrData[17] = $tabTrData[18];
		}
		
		if($tabTrData[19] == '租赁期限起止：'){
			$tabTrData[19] = $tabTrData[20];
		}
		
		if($tabTrData[21] == '地区类别：'){
			$tabTrData[21] = $tabTrData[22];
		}
		
		if($tabTrData[23] == '工商营业执照编号：'){
			$tabTrData[23] = '';
		}
		
		if($tabTrData[25] == '工商营业执照有效期：'){
			$tabTrData[25] = $tabTrData[26];
		}
		
		if($tabTrData[27] == '发证日期：'){
			$tabTrData[27] = $tabTrData[26];
		}	
		
		if($tabTrData[27] == '颁发机构：'){
			$tabTrData[27] = $tabTrData[28];
		}
		
		if($tabTrData[33] == '制证日期：'){
			$tabTrData[33] = $tabTrData[34];
		}
		
		if($tabTrData[33] == '制证日期：'){
			$tabTrData[33] = $tabTrData[34];
		}
		
		if($tabTrData[29] == '发证日期：'){
			$tabTrData[29] = $tabTrData[30];
		}
		
		if($tabTrData[35] == '有效期限起止：'){
			$tabTrData[35] = $tabTrData[36];
		}
		
		if($tabTrData[37] == '供货单位：'){
			$tabTrData[37] = $tabTrData[38];
			$tabTrData[41] = $tabTrData[42];
			$tabTrData[43] = $tabTrData[44];
			$tabTrData[45] = $tabTrData[46];
			$tabTrData[47] = $tabTrData[48];
			$tabTrData[49] = $tabTrData[50];
			$tabTrData[51] = @$tabTrData[52];
		}
		
		if($tabTrData[37] == '联系人姓名：'){
			$tabTrData[37] = $tabTrData[36];
			$tabTrData[41] = $tabTrData[40];
			$tabTrData[43] = $tabTrData[42];
			$tabTrData[45] = $tabTrData[44];
			$tabTrData[47] = $tabTrData[46];
			$tabTrData[49] = $tabTrData[48];
			$tabTrData[51] = @$tabTrData[50];
		}
		
		if($tabTrData[25] == '颁发机构：'){
			$tabTrData[25] = $tabTrData[24];
			$tabTrData[23] = '';
		}
		
		if($tabTrData[33] == '有效期限起止：'){
			$tabTrData[33] = $tabTrData[32];
		}
		
		if($tabTrData[29] == '当前生效状态：'){
			$tabTrData[29] = $tabTrData[28];
		}
		
		if($tabTrData[35] == '供货单位：'){
			$tabTrData[35] = $tabTrData[34];
		}
		
		
		$customer = array();
		$customer['license'] = $tabTrData[2];			//许可证号
		$customer['name'] = $tabTrData[4];				//企业（字号）名称
		$customer['legal'] = $tabTrData[6];				//经营者姓名
		$customer['enterprisetype'] = $tabTrData[8];	//企业类型
		$customer['scope'] = '卷烟';					//经营范围
		$customer['independent'] = $tabTrData[11];		//与住所相独立
		$customer['address'] = $tabTrData[13];			//经营场所地址
		$customer['ownership'] = $tabTrData[15];		//经营场地权属
		$customer['operatarea'] = $tabTrData[17];		//经营面积（平方米）
		$customer['leaseterm'] = $this->trimall($tabTrData[19]);		//租赁期限起止
		$customer['areacategory'] = $tabTrData[21];		//地区类别
		$customer['charter'] = $tabTrData[23];			//工商营业执照编号
		$customer['chartervalid'] = $tabTrData[25];		//工商营业执照有效期
		$customer['awardbody'] = $tabTrData[27];		//颁发机构
		$customer['issuingdate'] = $tabTrData[29];		//发证日期
		$customer['carddate'] = $tabTrData[33];			//制证日期
		$customer['valid'] = trim($tabTrData[35]);		//有效期限起止
		$customer['supplyunit'] = $tabTrData[37];		//供货单位
		$customer['contacts'] = $tabTrData[39];			//联系人姓名
		$customer['contactstel'] = $tabTrData[41];		//联系人电话
		$customer['grouptype'] = $tabTrData[43];		//特殊群体类型
		$customer['certificatetype'] = $tabTrData[45];	//身份证类型
		$customer['cardnumber'] = $tabTrData[47];		//身份证号码
		$customer['retailformat'] = @$tabTrData[49];		//零售业态
		$customer['cardaddress'] = @$tabTrData[51];		//身份证地址
		$customer['operating'] = 1;						//当前生效状态
		
		return $customer;
	}
	
	
	//从页面提取商户信息  王二凯
	public function extract_data($data){
		$data = strstr($data,'<table align="center"');
		list($data,) = explode('</table>',$data);
		//a($data);exit;
		//保证<td class="td_t"></td>可以匹配到
		$data = str_replace('<td class="td_t"></td>','<td class="td_t"> </td>',$data);
		
		preg_match_all('/<td.*>(.+)<\/td>/isU',$data,$tabTr);
		$tabTrData = $tabTr[1];
		$tabTrData = $this->arr_filter($tabTrData);
		
		//去除第一个值，第一个值为图片
		array_shift($tabTrData);
		
		$new_arr = array();
		//数据进行处理组装
		foreach($tabTrData as $key=>$val){
			$odd_key = !($key & 1) ? $key : ''; 
			$odd_val = !($key & 1) ? str_replace('：','',$val) : ''; 
			
			if(strlen($odd_val) >= 1){
				$new_key = $odd_key + 1;
				$new_arr[$odd_val] = @$tabTrData[$new_key];
			}
		}

		$customer = array();
		$customer['license'] = $new_arr['许可证号'];			//许可证号
		$customer['name'] = $new_arr['企业（字号）名称'];		//企业（字号）名称
		$customer['legal'] = $new_arr['经营者姓名'];			//经营者姓名
		$customer['enterprisetype'] = $new_arr['企业类型'];	    //企业类型
		$customer['scope'] = $new_arr['经营范围'];				//经营范围
		$customer['independent'] = $new_arr['与住所相独立'];	//与住所相独立
		$customer['address'] = $new_arr['经营场所地址'];		//经营场所地址
		$customer['ownership'] = $new_arr['经营场地权属'];		//经营场地权属
		$customer['operatarea'] = $new_arr['经营面积（平方米）'];		//经营面积（平方米）
		$customer['leaseterm'] = $new_arr['租赁期限起止'];		//租赁期限起止
		$customer['areacategory'] = $new_arr['地区类别'];		//地区类别
		$customer['charter'] = $new_arr['工商营业执照编号'];			//工商营业执照编号
		$customer['chartervalid'] = $new_arr['工商营业执照有效期'];		//工商营业执照有效期
		$customer['awardbody'] = $new_arr['颁发机构'];		//颁发机构
		$customer['issuingdate'] = $new_arr['发证日期'];		//发证日期
		$customer['carddate'] = $new_arr['制证日期'];			//制证日期
		$customer['valid'] = $new_arr['有效期限止'];		//有效期限起止
		$customer['supplyunit'] = $new_arr['供货单位'];		//供货单位
		$customer['contacts'] = $new_arr['联系人姓名'];			//联系人姓名
		$customer['contactstel'] = $new_arr['联系人电话'];		//联系人电话
		$customer['grouptype'] = $new_arr['特殊群体类型'];		//特殊群体类型
		$customer['certificatetype'] = $new_arr['身份证类型'];	//身份证类型
		$customer['cardnumber'] = $new_arr['身份证号码'];		//身份证号码
		$customer['retailformat'] = $new_arr['零售业态'];		//零售业态
		$customer['cardaddress'] = $new_arr['身份证地址'];		//身份证地址
		$customer['operating'] = $new_arr['当前生效状态'];		//当前生效状态
		
		//a($customer);exit;
		return $customer;
	}
	//过滤hrtml标签
	public function arr_filter($arr){
		$new_arr = array();
		foreach($arr as $key=>$val){
			$filter_key = $this->trimall(strip_tags($key));
			$new_arr[$filter_key] = $this->trimall(strip_tags($val));
		}
		return $new_arr;
	}
	
	//获取营销信息
	public function Marketinginformation($data){
		//销售信息
		//$datainfo = strstr($data,'<table width="98%"');
		$datainfo = strstr($data,'title="营销信息"');
		list($datainfo,) = explode('</table>',$datainfo);
		preg_match_all('/<td.*>(.+)<\/td>/isU',$datainfo,$tabTr);
		$tabTrData = $tabTr[1];
		$tabTrData = $this->arr_filter($tabTrData);
	
		$minfo = array();	
		$minfo['chain'] = $this->trimall($tabTrData[3]);				//客户代码
		$minfo['chain'] = $minfo['chain'] == '是' ? 1 : 0 ;
		$minfo['headquarters'] = $this->trimall($tabTrData[5]);			//总店地址
		$minfo['orderform'] = $this->trimall($tabTrData[7]);			//订货方式
		$minfo['orderingcycle'] = $this->trimall($tabTrData[9]);		//订货周期
		$minfo['ordertel'] = $this->trimall($tabTrData[11]);			//订货电话
		$minfo['settlement'] = $this->trimall($tabTrData[13]);			//结算方式
		$minfo['openbank'] = $this->trimall($tabTrData[15]);			//开户银行
		$minfo['bankaccount'] = $this->trimall($tabTrData[17]);			//银行账号
		$minfo['accountholder'] = $this->trimall($tabTrData[19]);		//开户人姓名
		$minfo['accountgender'] = $this->trimall($tabTrData[21]);		//开户人性别
		$minfo['accountcard'] = $this->trimall($tabTrData[23]);			//开户人身份证号
		$minfo['manager'] = $this->trimall($tabTrData[25]);				//客户经理
		$minfo['managertel'] = $this->trimall($tabTrData[27]);			//客户经理电话
		$minfo['supplygear'] = $this->trimall($tabTrData[29]);			//货源供应档位
		$minfo['level'] = $this->trimall($tabTrData[31]);				//经营规模
		
		//物流信息
		//$datainfo = strstr($data,'<table width="70%"');
		$datainfo = strstr($data,'title="物流信息"');
		list($datainfo,) = explode('</table>',$datainfo);
		preg_match_all('/<td.*>(.+)<\/td>/isU',$datainfo,$tabTr);
		$tabTrData = $tabTr[1];
		$tabTrData = $this->arr_filter($tabTrData);
		
		//a($tabTrData);exit;
		
		$minfo['deliverymode'] = $tabTrData[1];						//送货方式
		$minfo['deliverypoint'] = $tabTrData[3];					//是否代送点
		$minfo['deliveryman'] = @$tabTrData[5];						//送货员姓名
		$minfo['deliverytel'] = @$tabTrData[7];						//送货员电话
		
		//a($minfo);exit;
		
		return $minfo;
	}
	
	//市场监管数据提取
	public function marketregulatory($data){
		//a($data);
		//物流信息
		$datainfo = strstr($data,'title="市场监管"');
		list($datainfo,) = explode('</table>',$datainfo);
		preg_match_all('/<td.*>(.+)<\/td>/isU',$datainfo,$tabTr);
		$tabTrData = $tabTr[1];

		//获取租金
		preg_match_all('|value="(.*)"|isU',$tabTrData[2],$tabTr);
		$rent = $tabTr[1][0];

		//消费需求
		preg_match_all('|value="(.*)"|isU',$tabTrData[4],$tabTr);
		$consumerneeds = $tabTr[1][0];
		
		//场所邮编
		preg_match_all('|value="(.*)"|isU',$tabTrData[6],$tabTr);
		$postcode = $tabTr[1][0];
		
		//地理环境
		preg_match_all('|value="(.*)"|isU',$tabTrData[8],$tabTr);
		$environment = $tabTr[1][0];
		
		//商圈
		preg_match_all('|value="(.*)"|isU',$tabTrData[10],$tabTr);
		$tradingarea = $tabTr[1][0];
		
		//经营人籍贯
		preg_match_all('|value="(.*)"|isU',$tabTrData[12],$tabTr);
		$nativeplace = $tabTr[1][0];
		
		//主要消费群体
		preg_match_all('|value="(.*)"|isU',$tabTrData[14],$tabTr);
		$consumergroups = $tabTr[1][0];
		
		//地缘情况
		preg_match_all('|value="(.*)"|isU',$tabTrData[16],$tabTr);
		$geopoliticalsituation = $tabTr[1][0];
		
		//实际经营人姓名
		preg_match_all('|value="(.*)"|isU',$tabTrData[18],$tabTr);
		$actualoperator = $tabTr[1][0];
		
		//实际经营人现居地
		preg_match_all('|value="(.*)"|isU',$tabTrData[20],$tabTr);
		$actualaddress = $tabTr[1][0];
		
		//实际经营人手机号码：
		preg_match_all('|value="(.*)"|isU',$tabTrData[22],$tabTr);
		$actualtel = $tabTr[1][0];
		
		//卷烟经营面积（平米）
		preg_match_all('|value="(.*)"|isU',$tabTrData[24],$tabTr);
		$businessarea = $tabTr[1][0];
		
		//所属五级网格
		preg_match_all('|value="(.*)"|isU',$tabTrData[26],$tabTr);
		$grid = $tabTr[1][0];
		//坐标位置
		$map = $this->trimall(strip_tags($tabTrData[31]));
		list($mapx,$mapy) = explode('，',$map);
		//a($tabTrData);exit;
		
		$market = array();
		$market['rent'] = $rent;								//租金（元/年）
		$market['consumerneeds'] = $consumerneeds;				//消费需求
		$market['postcode'] = $postcode;						//场所邮编：
		$market['environment'] = $environment;					//地理环境
		$market['tradingarea'] = $tradingarea;					//商圈
		$market['nativeplace'] = $nativeplace;					//经营人籍贯
		$market['consumergroups'] = $consumergroups;			//主要消费群体
		$market['geopoliticalsituation'] = $geopoliticalsituation;	//地缘情况
		$market['actualoperator'] = $actualoperator;			//实际经营人姓名
		$market['actualaddress'] = $actualaddress;				//实际经营人现居地
		$market['actualtel'] = $actualtel;						//实际经营人手机号码：
		$market['tel'] = $actualtel;							//电话号码
		$market['businessarea'] = $businessarea;				//卷烟经营面积（平米）
		$market['grid'] = $grid;								//所属五级网格
		$market['mapx'] = $mapx;								//经度
		$market['mapy'] = $mapy;								//纬度
		
		return $market;
	}
	
	//同步商户数据
	public function import_customer($data,$customerStatus,$sgy_user_name,$cv=array()){
		/* echo(date('H:i:s').'-----------'.$data['name'].'...............................<br />');
		ob_flush();
		flush(); */
		
		$content = date('H:i:s').'--记录'.$cv->ROW_ID.'-----------'.$data['name'].'...............................<br />';
		$this->push_div_content('.scorpall',$content);

		//获取网格对应的用户和中队
		$grind_info = $this->dao->select('*')->from('t_comm_zm_grid')->where('id')->eq($data['grid'])->andWhere('status = 0')->fetch();
		
		$squadron = '';
		$manager = '';
		if($grind_info){
			$squadron = $grind_info->squadronid;
			$manager = $grind_info->userid;
		}
		
		//如果没有公司名称从中队回去
		if(!$data['awardbody']){
			$awardbody = $this->dao->select('b.id,b.squadron')->from('t_comm_zm_squadron')->alias('a')
							->leftJoin('t_comm_zm_area')->alias('b')->on('a.countrycode = b.countrycode')
							->where('a.squadron')->eq($squadron)
							->fetch();
			
			if($awardbody){
				$data['awardbody'] = $awardbody->squadron;
			}
		}
		
		$company_id = '';
		$company = $this->dao->select('*')->from('t_comm_dept')->where('org_name')->eq($data['awardbody'])->fetch();
		if($company){
			$company_id = $company->id;
		}

		//获取专卖人员信息
		$zm_user_id = '';
		$zm_tel = '';
		$zminfo = $this->dao->select('*')->from('t_comm_user')->where('employee_name')->eq($sgy_user_name)->fetch();
		if($zminfo){
			$zm_user_id = $zminfo->id;
			$zm_tel = $zminfo->mobile_phone;
		}
		
		//获取商户规模
		if($data['level'] == '大'){
			$level = 1;
		}else if($data['level'] == '中'){
			$level = 2;
		}else if($data['level'] == '小'){
			$level = 3;
		}else{
			$level = 0;
		}
		
		//获取商户信息
		$if_c = $this->dao->select('*')->from('t_comm_business')->where('license')->eq($data['license'])->andWhere('status = 0')->fetch();
		
		//证件变更信息
		$change = array();
		$time = date('Y-m-d H:i:s');
		
		if($if_c){
			 $this->dao->update('t_comm_business')
				->set('company')->eq($company_id)
				->set('name')->eq($data['name'])
				->set('legal')->eq($data['legal'])
				->set('address')->eq($data['address'])
				//->set('squadron')->eq($squadron)
				->set('manager')->eq($manager)
				//->set('grid')->eq(‘’)
				->set('level')->eq($level)
				->set('operating')->eq($customerStatus)
				->set('mapx')->eq($data['mapx'])
				->set('mapy')->eq($data['mapy'])
				->set('enterprisetype')->eq($data['enterprisetype'])
				->set('scope')->eq($data['scope'])
				->set('independent')->eq($data['independent'])
				->set('ownership')->eq($data['ownership'])
				->set('operatarea')->eq($data['operatarea'])
				->set('leaseterm')->eq($data['leaseterm'])
				->set('areacategory')->eq($data['areacategory'])
				->set('charter')->eq($data['charter'])
				->set('chartervalid')->eq($data['chartervalid'])
				->set('awardbody')->eq($data['awardbody'])
				->set('carddate')->eq($data['carddate'])
				->set('issuingdate')->eq($data['issuingdate'])
				->set('supplyunit')->eq($data['supplyunit'])
				->set('grouptype')->eq($data['grouptype'])
				->set('retailformat')->eq($data['retailformat'])
				->set('certificatetype')->eq($data['certificatetype'])
				//->set('cardnumber')->eq($data['cardnumber'])
				->set('cardaddress')->eq($data['cardaddress'])
				->set('chain')->eq($data['chain'])
				->set('headquarters')->eq($data['headquarters'])
				->set('orderform')->eq($data['orderform'])
				->set('orderingcycle')->eq($data['orderingcycle'])
				->set('ordertel')->eq($data['ordertel'])
				->set('settlement')->eq($data['settlement'])
				->set('openbank')->eq($data['openbank'])
				->set('bankaccount')->eq($data['bankaccount'])
				->set('accountholder')->eq($data['accountholder'])
				->set('accountgender')->eq($data['accountgender'])
				->set('accountcard')->eq($data['accountcard'])
				->set('supplygear')->eq($data['supplygear'])
				->set('deliverymode')->eq($data['deliverymode'])
				->set('deliverypoint')->eq($data['deliverypoint'])
				->set('deliveryman')->eq($data['deliveryman'])
				->set('deliverytel')->eq($data['deliverytel'])
				->set('rent')->eq($data['rent'])
				->set('consumerneeds')->eq($data['consumerneeds'])
				->set('postcode')->eq($data['postcode'])
				->set('environment')->eq($data['environment'])
				->set('tradingarea')->eq($data['tradingarea'])
				->set('nativeplace')->eq($data['nativeplace'])
				->set('consumergroups')->eq($data['consumergroups'])
				->set('geopoliticalsituation')->eq($data['geopoliticalsituation'])
				->set('actualoperator')->eq($data['actualoperator'])
				->set('actualaddress')->eq($data['actualaddress'])
				->set('actualtel')->eq($data['actualtel'])
				->set('businessarea')->eq($data['businessarea'])
				->set('contacts')->eq($data['contacts'])
				->set('contactstel')->eq($data['contactstel'])
				->set('valid')->eq($data['valid'])
				->set('cardnumber')->eq($cv->RETAIL_CID_NO)
				//->set('zm_user_name')->eq($sgy_user_name)
				//->set('zm_user_id')->eq($zm_user_id)
				//->set('zm_tel')->eq($zm_tel)
				->set('update_date')->eq($time)
				->set('state')->eq(1)
				->where('license')->eq($data['license'])
				->exec();
		}else{
			
			$id = $this->dao->uuid();
			 $this->dao->insert('t_comm_business')
				->set('id')->eq($id)
				->set('company')->eq($company_id)
				->set('license')->eq($data['license'])
				->set('name')->eq($data['name'])
				->set('legal')->eq($data['legal'])
				->set('address')->eq($data['address'])
				->set('squadron')->eq($squadron)
				->set('manager')->eq($manager)
				->set('grid')->eq('')
				->set('level')->eq($level)
				->set('operating')->eq($customerStatus)
				->set('mapx')->eq($data['mapx'])
				->set('mapy')->eq($data['mapy'])
				->set('enterprisetype')->eq($data['enterprisetype'])
				->set('scope')->eq($data['scope'])
				->set('independent')->eq($data['independent'])
				->set('ownership')->eq($data['ownership'])
				->set('operatarea')->eq($data['operatarea'])
				->set('leaseterm')->eq($data['leaseterm'])
				->set('areacategory')->eq($data['areacategory'])
				->set('charter')->eq($data['charter'])
				->set('chartervalid')->eq($data['chartervalid'])
				->set('awardbody')->eq($data['awardbody'])
				->set('carddate')->eq($data['carddate'])
				->set('issuingdate')->eq($data['issuingdate'])
				->set('supplyunit')->eq($data['supplyunit'])
				->set('grouptype')->eq($data['grouptype'])
				->set('retailformat')->eq($data['retailformat'])
				->set('certificatetype')->eq($data['certificatetype'])
				//->set('cardnumber')->eq($data['cardnumber'])
				->set('cardnumber')->eq($cv->RETAIL_CID_NO)
				->set('cardaddress')->eq($data['cardaddress'])
				->set('chain')->eq($data['chain'])
				->set('headquarters')->eq($data['headquarters'])
				->set('orderform')->eq($data['orderform'])
				->set('orderingcycle')->eq($data['orderingcycle'])
				->set('ordertel')->eq($data['ordertel'])
				->set('settlement')->eq($data['settlement'])
				->set('openbank')->eq($data['openbank'])
				->set('bankaccount')->eq($data['bankaccount'])
				->set('accountholder')->eq($data['accountholder'])
				->set('accountgender')->eq($data['accountgender'])
				->set('accountcard')->eq($data['accountcard'])
				->set('supplygear')->eq($data['supplygear'])
				->set('deliverymode')->eq($data['deliverymode'])
				->set('deliverypoint')->eq($data['deliverypoint'])
				->set('deliveryman')->eq($data['deliveryman'])
				->set('deliverytel')->eq($data['deliverytel'])
				->set('rent')->eq($data['rent'])
				->set('consumerneeds')->eq($data['consumerneeds'])
				->set('postcode')->eq($data['postcode'])
				->set('environment')->eq($data['environment'])
				->set('tradingarea')->eq($data['tradingarea'])
				->set('nativeplace')->eq($data['nativeplace'])
				->set('consumergroups')->eq($data['consumergroups'])
				->set('geopoliticalsituation')->eq($data['geopoliticalsituation'])
				->set('actualoperator')->eq($data['actualoperator'])
				->set('actualaddress')->eq($data['actualaddress'])
				->set('actualtel')->eq($data['actualtel'])
				->set('businessarea')->eq($data['businessarea'])
				->set('contacts')->eq($data['contacts'])
				->set('contactstel')->eq($data['contactstel'])
				->set('valid')->eq($data['valid'])
				->set('zm_user_name')->eq($sgy_user_name)
				->set('zm_user_id')->eq($zm_user_id)
				->set('zm_tel')->eq($zm_tel)
				->set('create_date')->eq($time)
				->set('state')->eq(1)
				->exec();
				
			//证件变更--新办
			/* $cid = $this->dao->uuid();
			$this->dao->insert('zm_document_change')
				->set('id')->eq($cid)
				->set('business')->eq($id)
				->set('changetype')->eq(1)
				->set('remind')->eq(0)
				->set('changetime')->eq(time())
				->set('addtime')->eq(time())
				->exec(); */
		}
		
	}

	public function updata_customer_operating($data){
		foreach($data as $v){
			echo(date('H:i:s').'-----------'.$v->companyName.'...............................<br />');
			ob_flush();
			flush();
			
			//证件变更数据
			$if_c = $this->dao->select('*')->from('zm_business')->where('license')->eq($v->licNo)->andWhere('status = 0')->fetch();
			$changetype = 0;
			if($if_c){
				if($if_c->operating != $v->nowEffectStatus){
					if($v->nowEffectStatus == 2705){
						$changetype = 4;
					}else if($v->nowEffectStatus == 2706){
						$changetype = 5;
					}else if($v->nowEffectStatus == 2702){
						$changetype = 6;
					}
				}
				
				if($changetype != 0){
					$cid = $this->dao->uuid();
					$this->dao->insert('zm_document_change')
						->set('id')->eq($cid)
						->set('business')->eq($if_c->id)
						->set('changetype')->eq($changetype)
						->set('remind')->eq(0)
						->set('changetime')->eq(time())
						->set('addtime')->eq(time())
						->exec();
				}
			}
			
			
			//更新商户营业状态
			$this->dao->update('zm_business')
				->set('operating')->eq($v->nowEffectStatus)
				->where('license')->eq($v->licNo)
				->exec();
		}
		
	}

	//更新商户部分数据
	public function updata_customer_Part_info($cv,$vs){
		//证件变更数据
		$if_c = $this->dao->select('*')->from('zm_business')->where('license')->eq($cv->LICENSE_NO)->andWhere('status = 0')->fetch();
		
		//证件变更信息
		$change = array();
		
		if($if_c){
			if($if_c->tel != $cv->TEL){
				$change['tel']['old'] = $cv->TEL;
				$change['tel']['new'] = $if_c->tel;
			}
			
			//添加变更信息
			if(!empty($change)){
				$cid = $this->dao->uuid();
				$this->dao->insert('zm_document_change')
					->set('id')->eq($cid)
					->set('business')->eq($if_c->id)
					->set('changetype')->eq(3)
					->set('remind')->eq(0)
					->set('changetime')->eq(time())
					->set('addtime')->eq(time())
					->exec();
					
				//添加变更详情
				foreach($change as $cskey => $c_value){
					$cxid = $this->dao->uuid();
					$this->dao->insert('zm_document_change_details')
						->set('id')->eq($cxid)
						->set('document')->eq($cid)
						->set('business')->eq($if_c->id)
						->set('changeitem')->eq($cskey)
						->set('original')->eq($c_value['old'])
						->set('newcon')->eq($c_value['new'])
						->set('addtime')->eq(time())
						->exec();
				}
			}
			
		}
		
		
		$this->dao->update('zm_business')
			->set('squadron')->eq($vs['squadronid'])
			->set('grid')->eq($vs['gride'])
			->set('market')->eq($vs['userid'])
			->set('tel')->eq($cv->TEL)
			->where('license')->eq($cv->LICENSE_NO)
			->exec();
	}
	
	public function update_customer_info($data){
		//a($data);exit;
		$chain = 0;					//连锁店
		if(!empty($data[11])){
			$chain = $data[11] == '是' ? 1 : 0;
		}
		
		$changename = 0;			//变更姓名商户	
		if(!empty($data[12])){
			$changename = 1;
		}
		
		$restshop = 0;				//放心店
		if(!empty($data[13])){
			$restshop = 1;
		}
		
		$areacode = $data[14];				//区内串码
		$illegaluser = $data[15];			//违法户
		
		$education = 0;				//教育培训
		if(!empty($data[16])){
			$education = 1;
		}
		
		$rectification = 0;			//停业整顿
		if(!empty($data[17])){
			$rectification = 1;
		}
		
		$violation = $data[18];				//违规时间及次数
		
		$this->dao->update('zm_business')
			->set('chain')->eq($chain)
			->set('changename')->eq($changename)
			->set('restshop')->eq($restshop)
			->set('areacode')->eq($areacode)
			->set('illegaluser')->eq($illegaluser)
			->set('education')->eq($education)
			->set('rectification')->eq($rectification)
			->set('violation')->eq($violation)
			->where('license')->eq($data[1])
			->exec();
	}
	
	public function insert_apcd_task_pool($data){
		
		$task_month = date('Y-m');
		//$this->dao->delete()->from('apcd_task_pool')->where('task_month')->eq($task_month)->exec();
		//a($data);exit;
		foreach($data as $v){
			echo(date('H:i:s').'-----------'.$v->ENT_NAME.'...............................<br />');
			ob_flush();
			flush();
			$res = $this->dao->select('*')->from('apcd_task_pool')->where('id')->eq($v->TASK_UUID)->andWhere('status = 0')->fetch();

			if($res){
				$this->dao->update('apcd_task_pool')
					->set('if_delay')->eq($v->IF_DELAY)
					->set('client_code')->eq($v->CLIENT_CODE)
					->set('grid_name')->eq($v->GRID_NAME)
					->set('task_month')->eq($v->TASK_MONTH)
					->set('org_code')->eq($v->ORG_CODE)
					->set('start_date')->eq($v->START_DATE)
					->set('task_status')->eq($v->TASK_STATUS)
					->set('if_have_license')->eq($v->IF_HAVE_LICENSE)
					->set('descs')->eq($v->DESC)
					->set('end_date')->eq($v->END_DATE)
					->set('grid_id')->eq($v->GRID_ID)
					->set('task_source')->eq($v->TASK_SOURCE)
					->set('task_source_name')->eq($v->TASK_SOURCE_NAME)
					->set('creater')->eq($v->CREATER)
					->set('license_no')->eq($v->LICENSE_NO)
					->set('client_name')->eq($v->CLIENT_NAME)
					->set('ent_name')->eq($v->ENT_NAME)
					->set('runid')->eq($v->RUN_UUID)
					->set('addtime')->eq(time())
					->where('id')->eq($v->TASK_UUID)
					->exec();
			}else{
				$this->dao->insert('apcd_task_pool')
					->set('id')->eq($v->TASK_UUID)
					->set('if_delay')->eq($v->IF_DELAY)
					->set('client_code')->eq($v->CLIENT_CODE)
					->set('grid_name')->eq($v->GRID_NAME)
					->set('task_month')->eq($v->TASK_MONTH)
					->set('org_code')->eq($v->ORG_CODE)
					->set('start_date')->eq($v->START_DATE)
					->set('task_status')->eq($v->TASK_STATUS)
					->set('if_have_license')->eq($v->IF_HAVE_LICENSE)
					->set('descs')->eq($v->DESC)
					->set('end_date')->eq($v->END_DATE)
					->set('grid_id')->eq($v->GRID_ID)
					->set('task_source')->eq($v->TASK_SOURCE)
					->set('task_source_name')->eq($v->TASK_SOURCE_NAME)
					->set('creater')->eq($v->CREATER)
					->set('license_no')->eq($v->LICENSE_NO)
					->set('client_name')->eq($v->CLIENT_NAME)
					->set('ent_name')->eq($v->ENT_NAME)
					->set('runid')->eq($v->RUN_UUID)
					->set('addtime')->eq(time())
					->exec();
			}
					
		}
		
		echo(date('H:i:s').'-----------完成...............................<br />');
		ob_flush();
		flush();
		
	}
	
	//发送短信
	public function msg_send($userid){
		$sms = $this->app->loadClass('yunxin');
		
		//查询日计划用户
		$user = $this->dao->select('b.photo')->from('apcd_user')->alias('a')
			->leftJoin('zm_user')->alias('b')->on('a.xcyc_user_id = b.id')
			->where('a.apcd_app_userid')->eq($userid)
			->andWhere('b.status = 0')
			->fetchAll();
		
		$phone = array();
		if($user){
			foreach($user as $v){
				//发送手机号
				$phone[] = $v->phone;
			}
		}
		//$phone = array('18536812465');
		$phone = json_encode($phone);
		
		$templateid = 3062320;
		$params = '';
		
		$data['templateid'] = $templateid;
		$data['mobiles'] = $phone;
		$data['params'] = $params;
		
		$res = $sms->send_sms($data);
		return $res;
	}
	
	//获取任务池执行商户
	public function get_task_pool_exec_customer($userid){
		$task_pool_customer = $this->dao->select('a.id')->from('apcd_task_pool')->alias('a')
			->leftJOin('zm_grid')->alias('b')->on('a.grid_id = b.id')
			->leftJOin('apcd_user')->alias('c')->on('b.userid = c.id')
			->where('c.apcd_app_userid')->eq($userid)
			->andWhere('a.dayplan = 1 and a.task_status = 1')
			->fetchAll();
			
		$task_id = array();
		foreach($task_pool_customer as $v){
			$task_id[] = $v->id;
		}
		
		return $task_id;
	}
	
	function trimall($str){
		$qian=array(" ","　","\t","\n","\r",'&nbsp;','修正坐标');$hou=array("","","","","","","");
		return str_replace($qian,$hou,$str);    
	}
	
	
	//页面追加内容
	public function push_div_content($div,$content){
		echo('<script>
			var h = $(".scorpall")[0].offsetHeight;
			$("body").scrollTop(h); 
			$("'.$div.'").append("'.$content.'")
		</script>');
		ob_flush();
		flush();
	}
	
	//获取
	public function get_zcustomer(){
		$sql = "select license from t_comm_business where cardnumber like '%：%' ";
		return $this->dao->execute($sql);
	}
	
	/************案件数据更新************/
	public function updata_caseinfo($data){
		//a($data);exit;
		$res = $this->dao->select('id')->from('a_case_info')->where('id')->eq($data->caseUuid)->fetch();
		if($res){
			$this->dao->update('a_case_info')
					->set('idcard')->eq(@$data->cardnum)
					->set('license')->eq(@$data->license)
					->where('id')->eq($data->caseUuid)
					->exec();
		}
		
	}
	
	public function getLicenseByIdcard($idcard){
		$res = $this->dao->select('license')->from('t_comm_business')->where('cardnumber')->eq($idcard)->fetch();
		return !empty($res) ? $res->license :'';
	}
	
	//在办案件数据更新
	public function updata_caseinfo_zb($data){
		$this->dao->update('a_case_info')
				->set('cardnum')->eq(@$data->cardnum)
				->where('id')->eq($data->caseUuid)
				->exec();
	}
	
	public function get_caseinfo(){
		return $this->dao->select('id')->from('caseinfo')->where('status = 1')->fetchAll();
	}
	
	
	/************检查记录***********/
	public function marketRecord($data){
		$res = $this->dao->select('*')->from('market_record')->where('id')->eq($data->CHECK_UUID)->fetch();
		
		if($res){
			$this->dao->update('market_record')
					->set('signInTime')->eq($data->SIGN_IN_TIME)
					->set('signOutTime')->eq($data->SIGN_OUT_TIME)
					->set('licenseNo')->eq($data->LICENSE_NO)
					->set('userName')->eq($data->USER_NAME)
					->set('clientName')->eq($data->CLIENT_NAME)
					->set('signXY')->eq($data->SIGN_XY)
					->set('curentXY')->eq($data->CURENT_LOCATION_XY)
					->set('deviateDistance')->eq($data->DEVIATE_DISTANCE)
					->set('isDeviate')->eq($data->IS_DEVIATE)
					->set('shopName')->eq($data->SHOP_NAME)
					->set('deptCode')->eq($data->DEPT_CODE)
					->set('unitCode')->eq($data->UNIT_CODE)
					->set('addtime')->eq(time())
					->where('id')->eq($data->CHECK_UUID)
					->exec();

		}else{
			$this->dao->insert('market_record')
					->set('id')->eq($data->CHECK_UUID)
					->set('signInTime')->eq($data->SIGN_IN_TIME)
					->set('signOutTime')->eq($data->SIGN_OUT_TIME)
					->set('licenseNo')->eq($data->LICENSE_NO)
					->set('userName')->eq($data->USER_NAME)
					->set('clientName')->eq($data->CLIENT_NAME)
					->set('signXY')->eq($data->SIGN_XY)
					->set('curentXY')->eq($data->CURENT_LOCATION_XY)
					->set('deviateDistance')->eq($data->DEVIATE_DISTANCE)
					->set('isDeviate')->eq($data->IS_DEVIATE)
					->set('shopName')->eq($data->SHOP_NAME)
					->set('deptCode')->eq($data->DEPT_CODE)
					->set('unitCode')->eq($data->UNIT_CODE)
					->set('addtime')->eq(time())
					->set('status')->eq(1)
					->exec();
		}
	}
	
	/************电子卷宗证件状态***********/
	public function certStatus($data){
		$res = $this->dao->select('*')->from('certStatus')->where('applyInfoUuid')->eq($data->applyInfoUuid)->fetch();
		
		if($res){
			$this->dao->update('certStatus')
					->set('applyTypeText')->eq($data->applyTypeText)
					->set('decideDateText')->eq($data->decideDateText)
					->set('decideDate')->eq($data->decideDate)
					->set('ecoType')->eq($data->ecoType)
					->set('bookbuildTime')->eq($data->bookbuildTime)
					->set('bookbuildTimeText')->eq($data->bookbuildTimeText)
					->set('auditUnitsName')->eq($data->auditUnitsName)
					->set('licNo')->eq($data->licNo)
					->where('applyInfoUuid')->eq($data->applyInfoUuid)
					->andwhere('status')->eq(1)
					->exec();

		}else{
			$this->dao->insert('certStatus')
					->set('id')->eq($data->applyInfoUuid)
					->set('applyInfoUuid')->eq($data->applyInfoUuid)
					->set('applyTypeText')->eq($data->applyTypeText)
					->set('decideDateText')->eq($data->decideDateText)
					->set('decideDate')->eq($data->decideDate)
					->set('ecoType')->eq($data->ecoType)
					->set('bookbuildTime')->eq($data->bookbuildTime)
					->set('bookbuildTimeText')->eq($data->bookbuildTimeText)
					->set('auditUnitsName')->eq($data->auditUnitsName)
					->set('licNo')->eq($data->licNo)
					->set('addtime')->eq(time())
					->set('status')->eq(1)
					->exec();
		}
	}
	
	//获取案件卷烟数据
	public function updata_case_goods($data){
		$res = $this->dao->select('*')->from('a_case_cigarette')->where('id')->eq($data->goodsDtlUuid)->fetch();
		
		if($res){
			$this->dao->update('a_case_cigarette')
					->set('case_id')->eq($data->caseUuid)
					->set('class')->eq($data->propTypeStr)
					->set('brand')->eq($data->goodsName)
					->set('unit')->eq($data->unit)
					->set('number')->eq($data->qty)
					->set('unit_price')->eq($data->price)
					->set('money')->eq($data->amt)
					->set('result')->eq($data->handleStyleStr)
					->set('propSubtypeStr')->eq($data->propSubtypeStr)
					->where('id')->eq($data->goodsDtlUuid)
					->exec();

		}else{
			$this->dao->insert('a_case_cigarette')
					->set('id')->eq($data->goodsDtlUuid)
					->set('case_id')->eq($data->caseUuid)
					->set('class')->eq($data->propTypeStr)
					->set('brand')->eq($data->goodsName)
					->set('unit')->eq($data->unit)
					->set('number')->eq($data->qty)
					->set('unit_price')->eq($data->price)
					->set('money')->eq($data->amt)
					->set('result')->eq($data->handleStyleStr)
					->set('propSubtypeStr')->eq($data->propSubtypeStr)
					->exec();
		}
	}
	
	
	public function get_casegoods(){
		return $this->dao->select('id')->from('a_case_cigarette')->where('status = 1')->fetchAll();
	}
	
	public function updata_goods_code($data){
		$res = $this->dao->select('*')->from('case_goods_code')->where('id')->eq($data->bitcodeUuid)->fetch();
		
		if($res){
			$this->dao->update('case_goods_code')
					->set('case_id')->eq($data->caseUuid)
					->set('af16bitcode')->eq($data->af16bitcode)
					->set('bf16bitcode')->eq($data->bf16bitcode)
					->set('goodsDtlUuid')->eq($data->goodsDtlUuid)
					->set('addtime')->eq(time())
					->where('id')->eq($data->bitcodeUuid)
					->exec();

		}else{
			$this->dao->insert('case_goods_code')
					->set('id')->eq($data->bitcodeUuid)
					->set('case_id')->eq($data->caseUuid)
					->set('af16bitcode')->eq($data->af16bitcode)
					->set('bf16bitcode')->eq($data->bf16bitcode)
					->set('goodsDtlUuid')->eq($data->goodsDtlUuid)
					->set('addtime')->eq(time())
					->exec();
		}
	}
	
	/******案件信息过去******/
	//案件基础信息入库
	public function insert_base_info($data){
		
		foreach($data as $v){
		    $cainfo = $this->if_exeit_case($v->caseUuid);
		    
		    if($cainfo){
		        $this->dao->update('a_case_info')
					//->set('case_name')->eq($v->regDocNo)
					->set('case_name')->eq($v->fullDocNo)
					->set('happen_time')->eq($v->caseDate)
					->set('case_time')->eq($v->caseDate1)
					->set('end_time')->eq($v->finshDate)
					->set('case_address')->eq($v->casePlace)
					->set('case_reason')->eq($v->causeOfAction)
					->set('case_info')->eq($v->caseBrief1)
					->set('deal_user')->eq($v->undertaker)
					->set('deal_unit')->eq($v->orgShortname)
					->set('deal_depart')->eq($v->deptName)
					->set('case_money')->eq($v->realCount)
					->set('source_type')->eq(1)
					->set('cast_type')->eq($v->handleProc)
					->set('case_code')->eq($v->caseCode)
					->set('party')->eq($v->party)
					->set('area')->eq($v->orgShortname)
					->set('addtime')->eq(time())
					->where('id')->eq($v->caseUuid)
					->exec();
		    }else{
		        $this->dao->insert('a_case_info')
					->set('id')->eq($v->caseUuid)
					//->set('case_name')->eq($v->regDocNo)
					->set('case_name')->eq($v->fullDocNo)
					->set('happen_time')->eq($v->caseDate)
					->set('case_time')->eq($v->caseDate1)
					->set('end_time')->eq($v->finshDate)
					->set('case_address')->eq($v->casePlace)
					->set('case_reason')->eq($v->causeOfAction)
					->set('case_info')->eq($v->caseBrief1)
					->set('deal_user')->eq($v->undertaker)
					->set('deal_unit')->eq($v->orgShortname)
					->set('deal_depart')->eq($v->deptName)
					->set('case_money')->eq($v->realCount)
					->set('source_type')->eq(1)
					->set('cast_type')->eq($v->handleProc)
					->set('area')->eq($v->orgShortname)
					->set('case_code')->eq($v->caseCode)
					->set('party')->eq($v->party)
					->set('addtime')->eq(time())
					->exec();
		    }
		    
			
			$this->push_div_content('.scorpall',$v->caseUuid.'----'.date('H:i:s').'.............................................<br />');
			//echo $v->caseUuid.'----'.date('H:i:s').'-----<br/>';
			ob_flush();
			flush();
		}
		
	}
	
		//三统一案件数据是否存在
	public function if_exeit_case($caseUuid){
	    return $this->dao->select('*')->from('a_case_info')
	                ->where('id')->eq($caseUuid)
	                ->fetch();
	}
	
	
	//添加涉案人员
	public function insert_suspect_info($data){
		
		foreach($data as $v){
			$gender = '未知';
			if($v->sex == 1){
				$gender = '男性';
			}else if($v->sex == 0){
				$gender = '女性';
			}
			
			//根据证件号判断嫌疑人是否存在
			$suspect = $this->dao->select('*')->from('a_suspect')->where('id')->eq($v->partyUuid)->fetch();
			
			if($suspect){
				$this->dao->update('a_suspect')
					->set('name')->eq($v->nameOrg)
					->set('gender')->eq($gender)
					->set('cardid')->eq($v->idCard)
					->set('domicile')->eq($v->idCardAddress)
					->set('residence')->eq($v->busiAddress)
					->set('tel')->eq($v->phone)
					->set('business')->eq($v->duty)
					/* ->set('source_province')->eq($_SESSION['source_province'])
					->set('source_city')->eq($_SESSION['source_city'])
					->set('source_area')->eq($_SESSION['source_area']) */
					->set('source_type')->eq(1)
					->set('addtime')->eq(time())
					->where('id')->eq($v->partyUuid)
					->exec();
			}else{
				$this->dao->insert('a_suspect')
					->set('id')->eq($v->partyUuid)
					->set('name')->eq($v->nameOrg)
					->set('gender')->eq($gender)
					->set('cardid')->eq($v->idCard)
					->set('domicile')->eq($v->idCardAddress)
					->set('residence')->eq($v->busiAddress)
					->set('tel')->eq($v->phone)
					->set('business')->eq($v->duty)
					/* ->set('source_province')->eq($_SESSION['source_province'])
					->set('source_city')->eq($_SESSION['source_city'])
					->set('source_area')->eq($_SESSION['source_area']) */
					->set('source_type')->eq(1)
					->set('addtime')->eq(time())
					->exec();
				
				$suspect_id = $v->partyUuid;
				
				$cid = $this->dao->uuid();
    			$this->dao->insert('a_suspect_to_case')
    					->set('id')->eq($cid)
    					->set('case_id')->eq($v->caseUuid)
    					->set('suspect_id')->eq($suspect_id)
    					->set('addtime')->eq(time())
    					->exec();	
			}
			
			
					
		}
		
	}
	
	//添加车辆
	public function insert_case_car($data,$caseUuid){
	    $car_info = $this->dao->select('*')->from('a_case_car')->where('case_id')->eq($caseUuid)->fetchAll();
	    if($car_info){
	        $this->dao->delete()->from('a_case_car')->where('case_id')->eq($caseUuid)->exec();
	    }
	    
		foreach($data as $v){
			$id = $this->dao->uuid();
			$this->dao->insert('a_case_car')
					->set('id')->eq($id)
					->set('case_id')->eq($caseUuid)
					->set('carNum')->eq($v->carNum)
					->set('carStyleStr')->eq($v->carStyleStr)
					->set('dicCarTypeStr')->eq($v->dicCarTypeStr)
					->set('lstModiTime')->eq($v->lstModiTime)
					->set('addtime')->eq(time())
					->exec();
		}
		
	}
	
	//添加卷烟
	public function insert_cigarette_info($data){
	     //判断卷烟信息是否存在，存在先删除卷烟信息和32位码信息
	    $cinfo = $this->dao->select('*')->from('a_case_cigarette')->where('case_id')->eq($data[0]->caseUuid)->fetchAll();
	    if($cinfo){
	        $this->dao->delete()->from('a_case_cigarette')->where('case_id')->eq($data[0]->caseUuid)->exec();
	        $this->dao->delete()->from('a_case_cigarette_code')->where('case_id')->eq($data[0]->caseUuid)->exec();
	    }
	    
		foreach($data as $v){
			$cid = $this->dao->uuid();
			$this->dao->insert('a_case_cigarette')
					->set('id')->eq($cid)
					->set('case_id')->eq($v->caseUuid)
					->set('class')->eq($v->propTypeStr)
					->set('brand')->eq($v->goodsName)
					->set('unit')->eq($v->unit)
					->set('number')->eq($v->qty)
					->set('unit_price')->eq($v->amt)
					->set('money')->eq($v->allCount)
					->set('result')->eq($v->handleStyleStr)
					->set('addtime')->eq(time())
					->exec();	
					
			//$this->insert_cig_code($v,$cid);
		}
		
	}
	
	public function insert_cig_code($cigarette_data,$cid){
	    //获取下行码
		$code_url = $this->regieapp_case.'tCCiga32bitCode/list';
		
	    $code_post = array();
	    $code_post['prodUuid'] = $cigarette_data->goodsUuid;
	    $code_post['goodsDtlUuid'] = $cigarette_data->goodsDtlUuid;
	    $code_post['queryMe'] = false;
	    $code_post['_search'] = false;
	    $code_post['pageSize'] = 1000;
	    $code_post['pageNo'] = 1;
	    $code_post['orderFields'] = 'bitcodeSerialNumber';
	    $code_post['order'] = 'asc';
	    $code_post['isEdit'] = true;
	    
		$cigarette_code = $this->http_request_post($code_url,$code_post);
	    //$cigarette_code = $this->p->curl($code_url,'POST',$code_post,false,1);	//下行码数据
	    $cigarette_code = json_decode($cigarette_code);
	    //a($cigarette_code);exit;
	    if($cigarette_code->total > 0){
	        foreach($cigarette_code->rows as $v){
	            $id = $this->dao->uuid();
    			$this->dao->insert('a_case_cigarette_code')
    					->set('id')->eq($id)
    					->set('case_id')->eq($v->caseUuid)
    					->set('smoke_id')->eq($cid)
    					->set('acode')->eq($v->af16bitcode)
    					->set('bcode')->eq($v->bf16bitcode)
    					->set('number')->eq($v->bitcodeSerialNumber)
    					->set('addtime')->eq(time())
    					->exec();
	        }
	        
	    }
		
	}
	
	//更新零售户诚信的等j
	public function update_fath_level($license,$faith_level,$laws_level,$laws_score,$promise_level,$promise_score){
		$this->dao->update('t_comm_business')
				->set('faith_level')->eq($faith_level) //诚信等级
				->set('laws_level')->eq($laws_level) //守法守规等级
				->set('laws_score')->eq($laws_score) //守法守规得分
				->set('promise_level')->eq($promise_level) //守约守信等级
				->set('promise_score')->eq($promise_score) //守约守信得分
				->where('license')->eq($license)
				->exec();
	}
	
	//添加零售户chengxing等级
	public function insert_fath_level_details($license,$month,$type,$details){
		$create_date = date('Y-m-d H:i:s');
		$da = $this->dao->select('*')->from('t_comm_business_fath_details')
				->where('license')->eq($license)
				->andWhere('month')->eq($month)
				->andWhere('type')->eq($type)
				->fetchAll();
		
		if($da){
			$this->dao->delete()->from('t_comm_business_fath_details')
				->where('license')->eq($license)
				->andWhere('month')->eq($month)
				->andWhere('type')->eq($type)
				->exec();
		}
		
		foreach($details as $v){
			$id = $this->dao->uuid();
			$this->dao->insert('t_comm_business_fath_details')
					->set('id')->eq($id)
					->set('month')->eq($month) //月份
					->set('license')->eq($license)
					->set('type')->eq($type) //1、守约守信等级详情2、守法守规等级详情
					->set('targetName')->eq($v->targetName) //指标名称
					->set('parameterName')->eq($v->parameterName)//参数名
					->set('warnValue')->eq($v->scoreValue) //分值
					->set('scoreValid')->eq($v->scoreValid) //是否有效1、有效0、
					->set('create_date')->eq($create_date)
					->exec();
					
		}
		
		
	}
	
	//添加真假烟数据
	public function insert_tfcig($start_date,$end_date,$details,$flag){
		
		
		$create_date = date('Y-m-d H:i:s');
		foreach($details as $v){
			if($v->COUNTY_NAME == ""){
				continue;
			}
			
			$this->push_div_content('.scorpall',$v->BF_16BITCODE.'.............................................<br />');
			
			$d = $this->dao->select('*')->from('a_tf_cigarette')
					->where('start_date')->eq($start_date)
					->andWhere('end_date')->eq($end_date)
					->andWhere('bf_16bitcode')->eq($v->BF_16BITCODE)
					->fetchAll();
			
			if($d){
				$this->dao->delete()->from('a_tf_cigarette')
						->where('start_date')->eq($start_date)
						->andWhere('end_date')->eq($end_date)
						->andWhere('bf_16bitcode')->eq($v->BF_16BITCODE)
						->exec();
			}
		
			$license = substr($v->AF_16BITCODE,4);
			$fj_date = date('Y-m-d',strtotime(date('202'.substr($v->BF_16BITCODE,0,5))));
			
			$id = $this->dao->uuid();
			$this->dao->insert('a_tf_cigarette')
					->set('id')->eq($id)
					->set('start_date')->eq($start_date)
					->set('end_date')->eq($end_date)
					->set('fj_date')->eq($fj_date)
					->set('flag')->eq($flag)
					->set('county_name')->eq($v->COUNTY_NAME)
					->set('city_name')->eq($v->CITY_NAME)
					->set('supply_name')->eq($v->SUPPLY_NAME)
					->set('brand_name')->eq($v->BRAND_NAME)
					->set('goods_name')->eq($v->GOODS_NAME)
					->set('strip_code')->eq($v->STRIP_CODE)
					->set('bf_16bitcode')->eq($v->BF_16BITCODE)
					->set('af_16bitcode')->eq($v->AF_16BITCODE)
					->set('branch_qty')->eq($v->BRANCH_QTY)
					->set('license')->eq($license)
					->set('create_date')->eq($create_date)
					->exec();
			
		}
	}
	
	//http请求
	public function http_request_get($lurl){
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$lurl);
		curl_setopt($ch, CURLOPT_HEADER,0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
		curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
		$res = curl_exec($ch);
		curl_close($ch); 
		
		return $res;
	}
	
	//http请求POST
	public function http_request_post($lurl,$post_data){
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$lurl);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_POST,1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
		curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
		$res = curl_exec($ch);
		curl_close($ch);
		
		return $res;
	}
	
}
